//
//  ChainSearchHistoryTagCell.m
//  Chain
//
//  Created by zhaosh on 2018/4/16.
//  Copyright © 2018年 zhaosh. All rights reserved.
//

#import "ChainSearchHistoryTagCell.h"

@interface ChainSearchHistoryTagCell()

@property (nonatomic,strong)UILabel *titleLb;
@property (nonatomic,strong)UIButton *allBtn;
@end

@implementation ChainSearchHistoryTagCell

#pragma mark converse init method
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"ProjectScreenCell";
    ChainSearchHistoryTagCell *cell = (ChainSearchHistoryTagCell*)[tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil){
        cell = [[ChainSearchHistoryTagCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self setupSubviews];
    }
    return self;
}

-(void)setupSubviews{
    self.tagListView = [JCTagListView new];
    self.tagListView.canSelectTags = YES;
    
    self.tagListView.tagCornerRadius = 2.0f;
    [self.contentView addSubview:self.tagListView];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.tagListView.frame = CGRectMake(0, 0, ScreenWidth-10, self.height);
    self.tagListView.backgroundColor = [UIColor yellowColor];
    [self.tagListView.tags removeAllObjects];
    [self.tagListView.tags addObjectsFromArray:self.array];
    
    if (self.defaultSelectedTags) {
        [self.tagListView.selectedTags removeAllObjects];
        if ([self.defaultSelectedTags isKindOfClass:[NSArray class]]) {
            [self.tagListView.selectedTags addObjectsFromArray:self.defaultSelectedTags];
        }else{
            [self.tagListView.selectedTags addObject:self.defaultSelectedTags];
        }
    }
    if (self.array && self.array.count>0) {
        [self.tagListView.collectionView reloadData];
    }
}

+(CGFloat)getCellHeightWithItem:(NSMutableArray *)item aView:(JCTagListView*)tagListView layout:(JCCollectionViewTagFlowLayout*)layout
{
    tagListView = [[JCTagListView alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth-10, 130)];
    tagListView.backgroundColor = [UIColor redColor];
    tagListView.canSelectTags = YES;
    
    tagListView.tagCornerRadius = 2.0f;
    
    [tagListView.tags addObjectsFromArray:item];
    [tagListView.selectedTags addObjectsFromArray:@[]];
    
    [tagListView.collectionView setCollectionViewLayout:layout];
    
    [layout prepareLayout];
    CGFloat heigth = [layout collectionViewContentSize].height;
    
    return heigth+15;
}
@end
